<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Imports image pixels</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="imagick.implodeimage.html">« Imagick::implodeImage</a></li>
      <li style="float: right;"><a href="imagick.inversefouriertransformimage.html">Imagick::inverseFourierTransformImage »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.imagick.html">Imagick</a></li>
    <li>Imports image pixels</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="imagick.importimagepixels" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Imagick::importImagePixels</h1>
  <p class="verinfo">(PECL imagick 2 &gt;= 2.3.0, PECL imagick 3)</p><p class="refpurpose"><span class="refname">Imagick::importImagePixels</span> &mdash; <span class="dc-title">Imports image pixels</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-imagick.importimagepixels-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Imagick::importImagePixels</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$x</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$y</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$width</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$height</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$map</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">int</span> <code class="parameter">$storage</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">array</span> <code class="parameter">$pixels</code></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Imports pixels from an array into an image. The <code class="parameter">map</code> is usually
   &#039;RGB&#039;. This method imposes the following constraints for the parameters: amount of pixels
   in the array must match <code class="parameter">width</code> x <code class="parameter">height</code> x length of the map.
   此方法在Imagick基于ImageMagick 6.4.5以上版本编译时可用。
  </p>

 </div>


 <div class="refsect1 parameters" id="refsect1-imagick.importimagepixels-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">x</code></dt>

     <dd>

      <p class="para">
       The image x position
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">y</code></dt>

     <dd>

      <p class="para">
       The image y position
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">width</code></dt>

     <dd>

      <p class="para">
       The image width
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">height</code></dt>

     <dd>

      <p class="para">
       The image height
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">map</code></dt>

     <dd>

      <p class="para">
       Map of pixel ordering as a string. This can be for example <code class="literal">RGB</code>.
       The value can be any combination or order of R = red, G = green, B = blue, A = alpha (0 is transparent), 
       O = opacity (0 is opaque), C = cyan, Y = yellow, M = magenta, K = black, I = intensity (for grayscale), P = pad.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">storage</code></dt>

     <dd>

      <p class="para">
       The pixel storage method. 
       Refer to this list of <a href="imagick.constants.html#imagick.constants.pixel" class="link">pixel constants</a>.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">pixels</code></dt>

     <dd>

      <p class="para">
       The array of pixels
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-imagick.importimagepixels-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>。
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-imagick.importimagepixels-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   错误时抛出 ImagickException。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-imagick.importimagepixels-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2790">
    <p><strong>示例 #1 <span class="methodname"><strong>Imagick::importImagePixels()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #FF8000">/*&nbsp;Generate&nbsp;array&nbsp;of&nbsp;pixels.&nbsp;2000&nbsp;pixels&nbsp;per&nbsp;color&nbsp;stripe&nbsp;*/<br /></span><span style="color: #0000BB">$count&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2000&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$pixels&nbsp;</span><span style="color: #007700">=&nbsp;<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">array_merge</span><span style="color: #007700">(</span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(array(),&nbsp;</span><span style="color: #0000BB">$count</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(array(),&nbsp;</span><span style="color: #0000BB">$count</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">),&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(array(),&nbsp;</span><span style="color: #0000BB">$count</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(array(),&nbsp;</span><span style="color: #0000BB">$count</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">255</span><span style="color: #007700">),<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">array_pad</span><span style="color: #007700">(array(),&nbsp;</span><span style="color: #0000BB">$count</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/*&nbsp;Width&nbsp;and&nbsp;height.&nbsp;The&nbsp;area&nbsp;is&nbsp;amount&nbsp;of&nbsp;pixels&nbsp;divided<br />&nbsp;&nbsp;&nbsp;by&nbsp;three.&nbsp;Three&nbsp;comes&nbsp;from&nbsp;'RGB',&nbsp;three&nbsp;values&nbsp;per&nbsp;pixel&nbsp;*/<br /></span><span style="color: #0000BB">$width&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$height&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">pow</span><span style="color: #007700">((</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$pixels</span><span style="color: #007700">)&nbsp;/&nbsp;</span><span style="color: #0000BB">3</span><span style="color: #007700">),&nbsp;</span><span style="color: #0000BB">0.5</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Create&nbsp;empty&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">$im&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">newImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'gray'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;Import&nbsp;the&nbsp;pixels&nbsp;into&nbsp;image.<br />&nbsp;&nbsp;&nbsp;width&nbsp;*&nbsp;height&nbsp;*&nbsp;strlen("RGB")&nbsp;must&nbsp;match&nbsp;count($pixels)&nbsp;*/<br /></span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">importImagePixels</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"RGB"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Imagick</span><span style="color: #007700">::</span><span style="color: #0000BB">PIXEL_CHAR</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$pixels</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;output&nbsp;as&nbsp;jpeg&nbsp;image&nbsp;*/<br /></span><span style="color: #0000BB">$im</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setImageFormat</span><span style="color: #007700">(</span><span style="color: #DD0000">'jpg'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type:&nbsp;image/jpg"</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$im</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/c0d23d2d6769e53e24a1b3136c064577-importimagepixels.jpg" alt="Output of example : Imagick::importImagePixels()" width="100" height="100" />
     </div>
    </div>
   </div>
  </p>
 </div>




</div></div></div></body></html>